<?php
/**
 * Simple meta file append action for the burreaucracy plugin
 *
 * @author Stephane Chamberland <dokuwiki@meteokid.ca>
 */
class syntax_plugin_bureaucracy_action_metafile extends syntax_plugin_bureaucracy_actions {

    function run($data, $thanks, $argv, &$errors) {
        global $ID;

        $suffix = array_shift($argv);

        $buro =& plugin_load('helper', 'bureaucracy');
        if (!is_null($buro) && $buro->isEnabled()) {
            $mypost = $this->buro->_collectpost($data);

            //Save to metafile
            $file = metaFN($ID, '.'.$suffix);
            if (@file_exists($file)) {
                $fields = unserialize(io_readFile($file, false));
            } else {
                $fields = array();
            }
            $fields[$mypost['uid']] = $mypost;
            if (@io_saveFile($file, serialize($fields))) return $thanks;
        }
        return '';
    }

}
// vim:ts=4:sw=4:et:enc=utf-8:
